<template>
    <div>
        <div class="tableHeader">
            <div class="tableHeaderTitle">下载库分类列表</div>
            <div class="tableHeaderMenu">
                <el-button-group>
                    <el-button icon="el-icon-refresh" @click="refreshData" size="mini"></el-button>
                </el-button-group>
            </div>
        </div>

        <el-table ref="multipleTable" :data="columnData" tooltip-effect="dark" style="width: 100%">
            <el-table-column label="序号" type="index" width="80"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" prop="cdc_name" label="分类名称"></el-table-column>
            <el-table-column label="操作" fixed="right" width="260">
                <template slot-scope="scope">
                    <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import {mapState, mapMutations} from 'vuex'

    export default {
        //数据源
        data() {
            return {
                lastFid: 0,
            }
        },
        //初始化函数
        mounted() {
            this.initData();
        },
        //计算属性
        computed: {
            ...mapState({
                columnData: state => state.DownloadCategoryModule.columnData
            }),
        },
        //组件方法
        methods: {
            initData() {
                this.$myLoading.startLoading();
                this.$http.getHttp(
                    this.$API.cmsDownloadCategorySearch + "/skip/0/limit/1000/cdc_is_delete/0",
                    rs => {
                        console.log(rs);
                        this.$myLoading.endLoading();
                        this.$store.commit("DownloadCategoryModule/updateColumnData", rs.data);
                    }
                );
            },

            refreshData() {
                this.initData();
            },
            handleEdit(index, item) {
                this.$router.push({
                    path: "/editDownloadCategory",
                    query: {
                        cdc_id: item.cdc_id
                    }
                });
            },
            handleDelete(index, item) {
                var params = {
                    delete_where: 'cdc_id',
                    cdc_id: item.cdc_id,
                    cdc_is_delete:1
                };
                this.$myPop.confirmBox("确认操作", "确定要删除该分类吗？", () => {
                    this.$myLoading.startLoading();
                    this.$http.postHttp(this.$API.cmsDownloadCategoryDelete, params, rs => {
                        this.$myLoading.endLoading();
                        this.$myPop.SuccessMessage();
                        this.initData();
                    });
                });
            }
        },
    }
</script>

<style lang="stylus" scoped>
    @import '~PUBLIC_CSS';
</style>